<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml">
<html>
<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="Layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="Layuimini/css/public.css" media="all">
    <link href="chongwu/collect.css" rel="stylesheet" type="text/css" />
    <style>
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-row">
            <div class="layui-col-md7">
                <div class="layui-form layuimini-form">

                    <input type="hidden" name="id"  th:value="${id}"  value="" class="layui-input">

                    <div class="layui-form-item">
                        <label class="layui-form-label">当前账号</label>
                        <div class="layui-card-header" th:text="${username}"></div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label required">旧的密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="oldPassword" lay-verify="required" lay-reqtext="旧的密码不能为空" placeholder="请输入旧的密码"  value="" class="layui-input">
                            <tip>填写自己账号的旧的密码。</tip>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label required">新的密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="password" id="password" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请输入新的密码"  value="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label required">新的密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="newPassword" lay-verify="required" lay-reqtext="新的密码不能为空" placeholder="请再次输入新的密码"  value="" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn layui-btn-primary layui-border-green" lay-submit lay-filter="saveBtn">确认保存</button>

                            <button type="button" class="layui-btn layui-btn-primary layui-border-orange" id="resetBtn">重置</button>
                        </div>
                    </div>

                </div>
            </div>
            <div class="layui-col-md5">
                <div class="flip-wrapper" style="width: 250px;height: 250px;margin-left: 30px;margin-top: 20px" onclick="changeClass(this)">
                    <div class="flip-a">
                        <img class="coverd" style="width: 275px; height: 275px;" th:src="${avatar}" alt="图片加载失败">
                    </div>
                    <div class="flip-b">
                        <h1> [[${letter}]]</h1>
                    </div>
                </div>
            </div>
        </div>




    </div>
</div>
<script src="Layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="Layuimini/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>

    var isUp = true
    function changeClass(el) {
        if (isUp) {
            el.className = 'flip-wrapper is-flipped';
        } else {
            el.className = 'flip-wrapper';
        }
        isUp = !isUp
    }


    layui.use(['form','miniTab'], function () {
        var form = layui.form,
            layer = layui.layer,
            miniTab = layui.miniTab,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            var id = data.field.id;

            var oldPassword = data.field.oldPassword;  //原密码
            var password = data.field.password;     //输入的新密码
            var newPassword = data.field.newPassword;  //确认的新密码

            if(password!=newPassword){
                layer.tips("两次密码输入不一致!","#password",{tips: 1});
                return false;
            }
            //密码修改操作
            $.ajax({
                url:"superLoginUser/setPasswordById",
                type:"POST",
                data: {"id":id,"oldPassword":oldPassword,"password":password},
                success:function(result){
                    if(result.code==20000){
                        layer.msg('用户密码修改成功！',{
                            icon: 6,
                            time:2000
                        },function(){
                            // window.parent.location.reload();  //刷新父页面
                           // window.location.reload();
                            miniTab.deleteCurrentByIframe();
                        })
                    }else{
                       // layer.alert("原密码不正确！",{icon: 5});
                        layer.msg('原密码不正确,修改失败！',{icon: 5});
                        return false;
                    }


                }
            });

            return false;
        });


        $("#resetBtn").click(function () {
            $("input[name='oldPassword']").val("");
            $("input[name='password']").val("");
            $("input[name='newPassword']").val("");
            layer.msg("重置成功！", {
                time: 1000, //6s后自动关闭
                icon:6
            });
        })

    });
</script>

</body>
</html>